﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;

public partial class appleader_level_proList : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        MasApp.BLL.Check.CheckLogin();
        /*
        if (Session["organizationid"] != null)
        {
            DataTable dt = app.BLL.Search.SearchUsersIDNameName(int.Parse(Session["organizationid"].ToString()));
            Repeater1.DataSource = dt;
            Repeater1.DataBind();
        }
         * */
        if (!Page.IsPostBack)
        {
            if (Request["projectid"] == null)
            {
                MasApp.BLL.ResponseHelper.alert("非法链接", "../projects/addmission.aspx");
            }
            else
            {
                //DataTable dt = app.BLL.Search.SearchUsersIDNameName(int.Parse(Session["organizationid"].ToString()));
                int projectid = Convert.ToInt32(Request["projectid"].ToString());
                foreach (GridViewRow gr in GridView1.Rows)
                {
                    Label lb_username = (Label)gr.Cells[1].FindControl("Label2");
                    if (MasApp.BLL.Search.SearchHaveUsernameInLevelmission(lb_username.Text, projectid) > 0)
                    {
                        CheckBox cb = (CheckBox)gr.Cells[3].FindControl("CheckBox1");
                        cb.Checked = true;
                    }

                }
            }
        }
    }
    protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
    {
        int projectid = Convert.ToInt32(Request["projectid"].ToString());

        //app.Model.userrole ur = new app.Model.userrole();
        //ur.Roleid = 8;

        MasApp.Model.levelmission lm = new MasApp.Model.levelmission();
        lm.Projectid = projectid;
        lm.State = "未做的";

        foreach (GridViewRow gr in GridView1.Rows)
        {
            CheckBox cb = (CheckBox)gr.Cells[3].FindControl("CheckBox1");
            if (cb.Checked == true)
            {
                Label lb_username = (Label)gr.Cells[1].FindControl("Label2");
                if (MasApp.BLL.Search.SearchHaveUsernameInLevelmission(lb_username.Text, projectid) == 0)
                {
                    Label lb_userid = (Label)gr.Cells[0].FindControl("Label1");
                    //ur.Userid = int.Parse(lb_userid.Text);
                    lm.Actor = lb_username.Text;

                    //lm.Levelmissionid = app.BLL.reg.AddExpert(lm, ur);
                    lm.Levelmissionid = MasApp.BLL.reg.RegLevelMission(lm);
                    MasApp.BLL.ResponseHelper.alert("您已经选择用户为当前项目的评级专家（评估员）", "prolist.aspx?projectid=" + projectid.ToString());

                }
            }
            else
            {
                Label lb_username = (Label)gr.Cells[1].FindControl("Label2");
                if (MasApp.BLL.Search.SearchHaveUsernameInLevelmission(lb_username.Text, projectid) > 0)
                {
                    lm.Actor = lb_username.Text;
                    lm.Actorroleid = MasApp.BLL.Search.LevelMissionActorRoleID(lm);
                    MasApp.BLL.Delete.DeleteLevelExper(lm);
                    MasApp.BLL.ResponseHelper.alert("您已经选择用户为当前项目的评级专家（评估员）", "prolist.aspx?projectid=" + projectid.ToString());

                }
            }
        }
    }
}
